/**
 * 将对象转换为URL查询字符串
 * @param {Object} data - 需要转换的对象
 * @returns {string} - URL查询字符串
 */
export const queryStringUtils = (
  data: { [x: string]: string | number | boolean } | null
): string => {
  if (typeof data !== 'object' || data === null) {
    throw new Error('The input should be an object')
  }

  return (
    '?' +
    Object.keys(data)
      .map(
        (key) => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`
      )
      .join('&')
  )
}
